home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -coverdisks- / 126a / football / user / updatescores.rexx < prev    next >
OS/2 REXX Batch file  |  1999-05-22  |  6KB  |  199 lines

  1. /* ***********************************************************************
  2.  
  3.    EXTRACT PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       260996   Created. Extracts results from schedule.learn and then
  12.                     recreates schedule.df
  13.  1.1       270996   Tidied, with info messages. Changed to use new filenames.
  14.                     'Teams.sflearn' is read in, the data is extracted, saved
  15.                     and then sorted, reread and then updated in a much faster
  16.                     way. Previous took 35 secs whereas this took 5 secs! Also
  17.                     would not work because of problems in the loop as all
  18.                     data has to be in order and the counter was only changed
  19.                     when it put one in - SHOULD BE when there's a match
  20.                     regardless of whether its been played or not.
  21.  1.2       121196   Updated to accept arguments so it can become a component
  22.                     of FOOTBALL. Removed all messages.
  23.            131196   Added checks for files - if not found, exits without
  24.                     a message.
  25.            201196   Added Iterate as teams can now play each other more
  26.                     than twice so that other matches (to be played) aren't
  27.                     written over.
  28.  
  29. **************************************************************************
  30.  
  31. Procedure
  32. ---------
  33.  
  34. 1. Check files exist. Open Learn file and output file.
  35. 2. Read all data from Learn (without '*') and write to output file.
  36. 3. Close files.
  37. 4. Call external program to sort the output file.
  38. 5. Open output file and read into an array. Close file.
  39. 6. Delete output file.
  40. 7. Open Schedule file and read into an array. Close file.
  41. 8. Update Schedule array with data from Learn but only if a match hasn't
  42.    been played.
  43. 9. Write to Schedule file. Close file. Exit.
  44.  
  45. ************************************************************************** */
  46. ARG league_file
  47.  
  48. version      = 1
  49. input_file   = '.sflearn'
  50. input2_file  = '.sf'
  51. input3_file  = '.df'
  52. output_file  = 'Data/Teams.temp'
  53. autosched    = "*AUTOSCHD="
  54. separator    = '*'
  55. sdlines.     = '???'
  56. selines.     = '???'
  57. sdcount      = 0
  58. secount      = 0
  59. autos        = 0
  60. not_played   = '__   __'
  61. league_file  = "Data/" || league_file
  62.  
  63.  
  64. if exists(league_file || input_file) = 0  then exit
  65. if exists(league_file || input2_file) = 0 then exit
  66. if exists(league_file || input3_file) = 0 then exit
  67.  
  68. if open(datafile,league_file || input3_file,'r') then do
  69.    do while ~eof(datafile)
  70.       line = readln(datafile)
  71.       if pos(autosched,line) > 0 then
  72.          autos = 1
  73.    end
  74.    close(datafile)
  75. end
  76. else do
  77.    say
  78.    say "ERROR :    (UpdateScores)"
  79.    say
  80.    say "Cannot open '"league_file || input3_file"' for reading."
  81.    exit
  82. end
  83.  
  84. if autos = 1 then do
  85.    say
  86.    say "ERROR :    (UpdateScores)"
  87.    say
  88.    say "This definition file, "league_file||input3_file", uses a"
  89.    say "schedule definition file. It is automatically scheduled so"
  90.    say "this will not work. Use 'UpdateScheduleScores' instead."
  91.    say
  92.    exit
  93. end
  94.  
  95. if open(datafile,league_file || input_file,'r') then do
  96.    if open(datafile2,output_file,'w') then do
  97.       do while ~eof(datafile)
  98.          line = readln(datafile)
  99.          line = strip(line)
  100.          if pos(separator,line) = 0 & words(line) > 0 then
  101.             writeln(datafile2,line)
  102.       end
  103.       close(datafile2)
  104.    end
  105.    else do
  106.       say
  107.       say "ERROR :    (UpdateScores)"
  108.       say
  109.       say "Cannot create '"output_file"' for temporary sorting."
  110.       exit
  111.    end
  112.    close(datafile)
  113. end
  114. else do
  115.    say
  116.    say "ERROR :    (UpdateScores)"
  117.    say
  118.    say "Cannot open '"league_file || input_file"' for reading."
  119.    exit
  120. end
  121.  
  122. address command 'Exec/footsort T'
  123.  
  124. if open(datafile,output_file,'r') then do
  125.    do while ~eof(datafile)
  126.       line = readln(datafile)
  127.       line = strip(line)
  128.       if words(line) > 0 then do
  129.          secount         = secount + 1
  130.          selines.secount = line
  131.       end
  132.    end
  133.    close(datafile)
  134. end
  135. else do
  136.    say
  137.    say "ERROR :    (UpdateScores)"
  138.    say
  139.    say "Cannot open '"output_file"' for re-reading."
  140.    exit
  141. end
  142.  
  143. address command 'delete >NIL: 'output_file
  144.  
  145. sdcount = 1
  146. if open(datafile3,league_file || input2_file,'r') then do
  147.    do while ~eof(datafile3)
  148.        line = readln(datafile3)
  149.        line = strip(line)
  150.        sdlines.sdcount = line
  151.        sdcount         = sdcount + 1
  152.    end
  153.    close(datafile3)
  154. end
  155. else do
  156.    say
  157.    say "ERROR :    (UpdateScores)"
  158.    say
  159.    say "Cannot open '"league_file || input2_file"' for reading."
  160.    exit
  161. end
  162.  
  163. i    = 0
  164. done = 0
  165.  
  166. do j=1 to sdcount
  167.    shome = strip(substr(sdlines.j,1,30))
  168.    saway = strip(substr(sdlines.j,41,30))
  169.    do i=1 to secount
  170.       home  = strip(substr(selines.i,1,30))
  171.       away  = strip(substr(selines.i,41,30))
  172.       if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do
  173.          sdlines.j = selines.i
  174.          say ">>"selines.i"<<"
  175.          k = k + 1
  176.          leave
  177.       end
  178.    end
  179.    if k = secount then leave
  180. end
  181.  
  182. if open(datafile3,league_file || input2_file,'w') then do
  183.    do j=1 to sdcount-1
  184.       if j < sdcount-1 then
  185.          writeln(datafile3,sdlines.j)
  186.       else
  187.          writech(datafile3,sdlines.j)
  188.    end
  189.    close(datafile3)
  190. end
  191. else do
  192.    say
  193.    say "ERROR :    (UpdateScores)"
  194.    say
  195.    say "Cannot open '"league_file || input2_file"' for writing."
  196.    exit
  197. end
  198.  
  199. exit